package model;
public class PlayerCharacter{
    public static final int ONE_POINT_THRESHOLD = 1;
    public static final int TWO_POINT_THRESHOLD = 13;
    public static final int THREE_POINT_THRESHOLD = 16;
    public static final int FOUR_POINT_THRESHOLD = 17;
    
    public static final int MAX_ATTRIBUTE = 18;
    public static final int STARTING_POINTS = 32;
    
    private int maxAttribute;

    //the number of points in each stat
    public int[] attributes = {10,10,10,10,10,10};
    public int[] minAttributes = attributes.clone();
    public boolean[] racialBonus = {false,false,false,false,false,false};
    public int reducedAttribute;
    
    public int points;
    
    public PlayerCharacter() {
	
	maxAttribute = MAX_ATTRIBUTE;
	points = STARTING_POINTS;
	setReducedAttribute(0);
    }
    
    public boolean canIncreaseAttribute(Stats the_stat) {
	int statLevel = attributes[Stats.getInt(the_stat)];
	if (statLevel - (racialBonus[Stats.getInt(the_stat)]?2:0) < maxAttribute && getRequiredPoints(statLevel) <= points) {
	    return true;
	}
	return false;
    }
    
    public void setReducedAttribute(int attribute) {
	minAttributes[reducedAttribute] = 10;
	reducedAttribute = attribute;
	minAttributes[reducedAttribute] = 8;
	attributes = minAttributes.clone();
    }
    
    public boolean canSwitchReducedAttribute() {
	return (points == STARTING_POINTS && 
		!racialBonus[0] &&
		!racialBonus[1] && 
		!racialBonus[2] &&
		!racialBonus[3] &&
		!racialBonus[4] &&
		!racialBonus[5]);
    }
    
    public boolean canDecreaseAttribute(Stats the_stat) {
	int statLevel = attributes[Stats.getInt(the_stat)];
	if (statLevel - (racialBonus[Stats.getInt(the_stat)]?2:0)> minAttributes[Stats.getInt(the_stat)]) {
	    return true;
	} else {
	return false;
	}
    }
    
    public void increaseAttribute(Stats the_stat) {
	int stat = Stats.getInt(the_stat);
	int statLevel = attributes[stat];
	attributes[stat]++;
	points-=getRequiredPoints(statLevel - (racialBonus[Stats.getInt(the_stat)]?2:0));//replace pointThreshold
    }
    
    public void decreaseAttribute(Stats the_stat) {
	int stat = Stats.getInt(the_stat);
	int statLevel = attributes[stat];
	attributes[stat]--;
	points += getRequiredPoints(statLevel - 1 - (racialBonus[Stats.getInt(the_stat)]?2:0));
    }
    
    public void setRacialBonus(int attribute, boolean hasBonus) {
	racialBonus[attribute] = hasBonus;
	attributes[attribute] += (hasBonus?2:-2);
    }
    
    public int getRequiredPoints(int statLevel) {
	if (statLevel >= FOUR_POINT_THRESHOLD) {
	    return 4;
	} else if (statLevel >= THREE_POINT_THRESHOLD) {
	    return 3;
	} else if (statLevel >= TWO_POINT_THRESHOLD) {
	    return 2;
	} else {
	    return 1;
	}
    }
    
    public int getRequiredPointsbyStat(int the_attribute) {
	int statLevel = attributes[the_attribute] - (racialBonus[the_attribute]?2:0);
	
	if (statLevel >= FOUR_POINT_THRESHOLD) {
	    return 4;
	} else if (statLevel >= THREE_POINT_THRESHOLD) {
	    return 3;
	} else if (statLevel >= TWO_POINT_THRESHOLD) {
	    return 2;
	} else {
	    return 1;
	}
    }
    public void reset() {
	for(int i=0;i<6;i++) {
	    attributes[i] = 10;
	    racialBonus[i] = false;
	}
	setReducedAttribute(0);
	points = STARTING_POINTS;
    }
    
    public String toString() {
	String result = "";
	for(int i=0;i<6;i++) {
	    
	}
	return result;
    }
}